package cn.tedu.yxcar.product.service.impl;

import cn.tedu.yxcar.product.ex.CoolSharkServiceException;
import cn.tedu.yxcar.product.mapper.CarMapper;
import cn.tedu.yxcar.product.pojo.vo.ArticleSearchVO;
import cn.tedu.yxcar.product.pojo.vo.CarListVO;
import cn.tedu.yxcar.product.pojo.vo.CarShowVO;
import cn.tedu.yxcar.product.service.ICarService;
import cn.tedu.yxcar.product.web.JsonPage;
import cn.tedu.yxcar.product.web.ResponseCode;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class CarServiceImpl implements ICarService {

    @Autowired
    private CarMapper carMapper;

    @Override
    public List<CarListVO> carSearch(String keywords) {
        List<CarListVO> carListVOS = carMapper.carSearch(keywords);
        return carListVOS;
    }

    /*@Override
    public JsonPage<CarListVO> carSearch(Integer page, Integer pageSize,String keywords) {
        PageHelper.startPage(page,pageSize);
        List<CarListVO> carListVOS = carMapper.carSearch(keywords);
        return JsonPage.restPage(PageInfo.of(carListVOS));
    }*/

    @Override
    public List<CarShowVO> carShow() {
        List<CarShowVO> carShowVOList = carMapper.carShow();
        return carShowVOList;
    }

    @Override
    public List<CarShowVO> carShowByModel(String model) {
        List<CarShowVO> carShowVO = carMapper.carShowByModel(model);
        if (carShowVO == null){
            String message = "查询类别详情失败，尝试访问的数据不存在！";
            log.warn(message);
            throw new CoolSharkServiceException(ResponseCode.NOT_FOUND, message);
        }
        return carShowVO;
    }


}
